Skip to content

fix: handle trl compatibility for DataCollatorForCompletionOnlyLM#169

Closed
YashasviChaurasia wants to merge 1 commit intofoundation-model-stack:mainfrom
YashasviChaurasia:fix/trl-compatibility-aadp
Closed

fix: handle trl compatibility for DataCollatorForCompletionOnlyLM#169
YashasviChaurasia wants to merge 1 commit intofoundation-model-stack:mainfrom
YashasviChaurasia:fix/trl-compatibility-aadp

Conversation

@YashasviChaurasia
Copy link
Copy Markdown
Contributor

Handle different trl versions gracefully to fix ImportError when using trl >= 0.19.

Problem:

  • In trl < 0.19: DataCollatorForCompletionOnlyLM is exported from trl
  • In some trl >= 0.19 versions: May be moved or renamed
  • Current code fails with: ImportError: cannot import name 'DataCollatorForCompletionOnlyLM' from 'trl'

Solution:

  • Try importing from trl first (works for most versions)
  • Fallback to trl.trainer.utils if not found
  • Create placeholder class if neither works (allows plugin to load)

This unblocks training when using transformers v5 (which requires trl >= 0.19).

Fixes compatibility with:

  • transformers v5.x + trl v0.19+
  • Maintains backward compatibility with older trl versions

…lyLM

Handle different trl versions gracefully to fix ImportError when using trl >= 0.19.

Problem:
- In trl < 0.19: DataCollatorForCompletionOnlyLM is exported from trl
- In some trl >= 0.19 versions: May be moved or renamed
- Current code fails with: ImportError: cannot import name 'DataCollatorForCompletionOnlyLM' from 'trl'

Solution:
- Try importing from trl first (works for most versions)
- Fallback to trl.trainer.utils if not found
- Create placeholder class if neither works (allows plugin to load)

This unblocks training when using transformers v5 (which requires trl >= 0.19).

Fixes compatibility with:
- transformers v5.x + trl v0.19+
- Maintains backward compatibility with older trl versions

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant